module("myio", package.seeall);

local pin=4
function ioInit()   
    gpio.mode(pin, gpio.OUTPUT)
    gpio.write(pin, gpio.HIGH)
end

function On()
    gpio.write(pin, gpio.LOW)
end

function Off()
    gpio.write(pin, gpio.HIGH)
end

local t = nil
function ioRoll(tim)
    local flag = 1
    t = tmr.create()
    t:alarm(tim, tmr.ALARM_AUTO, function()
        if(flag == 1) then
            flag = 0
            gpio.write(pin, gpio.HIGH)
        else
            flag = 1
            gpio.write(pin, gpio.LOW)
        end
    end)
end

function STOP()
    Off()
    t:unregister()
    t=nil
end
